package demo.action;

import java.util.HashMap;

import javax.servlet.http.HttpServletRequest;

import njiandan.mvc.annotation.BaseMapping;
import njiandan.mvc.annotation.Mapping;
import njiandan.mvc.render.JsonRenderer;
import njiandan.mvc.render.TemplateRenderer;


@BaseMapping("/")
public class IndexCtrl {
	
	/**
	 * "/index" 和 "/"都可以访问到此方法
	 * @return
	 */
	@Mapping(urls={""}, method="get")
	public String index(){		
		return "hollow njiandan-mvc";
	}
	
	@Mapping(urls={"json"}, method="get")
	public JsonRenderer json(UserInfo u) {
		HashMap<String, Object> map = new HashMap<String, Object>();
		map.put("key1", "val1");
		map.put("key2", "val2");
		map.put("key3", u);
		
		return new JsonRenderer(map);
	}
	
	
	@Mapping(urls={"up"}, method="get")
	public String upload(){		
		
		return "<form action=\"upload\" enctype=\"multipart/form-data\" method=\"post\"><input type=\"file\" name=\"books\"/><br/> <button type=\"submit\">上传</button></form>";
	}
	
	@Mapping(urls={"up1"}, method="get")
	public TemplateRenderer upload2(){		
		
		return new TemplateRenderer("/upload.jsp");
	}
}

